package com.yorick.logic.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yorick.logic.entity.Account;
import com.yorick.logic.protobuf.Location;
import com.yorick.netty.messageListener.LogicService;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LocationServiceImpl implements LogicService {

    @Override
    public void task(byte[] data, ChannelHandlerContext ctx) throws InvalidProtocolBufferException {
        String account = ctx.channel().attr(AttributeKey.valueOf("account")).get().toString();
        Location.C2SLocation location = Location.C2SLocation.parseFrom(data);
        com.yorick.logic.entity.Location location1 = com.yorick.logic.entity.Location.builder()
                .x(location.getX())
                .y(location.getY())
                .r(location.getR())
                .build();
        Account.locations.put(account, location1);
    }
}
